package org.gw.building.repositories;

import org.gw.building.model.TermStuApply;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface TermStuApplyRepositories extends CrudRepository<TermStuApply, String> {

	@Query("from TermStuApply t where (t.user.uid like ?1 or t.user.name like ?1 or ?1 is null) and (t.user.grade = ?2 or ?2 is null)"
			+ " and (t.user.department = ?3 or ?3 is null) and (t.user.major = ?4 or ?4 is null)"
			+ " and (t.istxgb = ?5 or ?5 is null) and (t.issqtzs = ?6 or ?6 is null) and (t.status =?7 or ?7 is null)"
			+ " and (?7 is not null or t.status in ?8)")
	public Page<TermStuApply> queryTermStuApply(String xh, String grade, String department, String major, Integer isGB,
                                                Integer applyTZS, Integer status, List<Integer> statusList, Pageable pageable);

	@Query("select t from TermStuApply t, Term term where t.user.uid=?1  and  t.term = term and term.status=1")
	public TermStuApply findOneByTermAndStudentXh(String stu);

	@Query("select t.term.id , count(t.id) as ct from TermStuApply t where t.term.id in ?1  and  (?2 is null or t.status=?2) group by t.term.id")
	public List<Object> getCountByTermIdInAndStatus(String[] term, Integer status);

}
